﻿<div  id="server-status">
<h2>Server status</h2>
Past connection was
<div id="server-status-time">@ViewBag.ElapsedTime</div>
<div id="server-status-time-int" style="display: none;">@ViewBag.ElapsedTimeInt</div>

<script>
    function updateTimeFromServer() {;
        $('#server-status-time-int').load('/Widgets/ServerStatusAjax');
        elapsedTime = -1;
    }

    var elapsedTime = -1;
    function updateTime() {
        if (elapsedTime == -1)
            elapsedTime = $("#server-status-time-int").text();
        $('#server-status-time').text(ConvertIntTimeToTime(elapsedTime));
        elapsedTime++;
    }
    setInterval("updateTimeFromServer()", 10000);
    setInterval("updateTime()", 1000);

    function ConvertIntTimeToTime(time) {
        rem = time % 60;
        time = Math.floor(time / 60);
        result = rem;
        if (rem < 10)
            result = "0" + result;
        rem = time % 60;
        time = Math.floor(time / 60);
        result = rem + ":" + result;
        if (rem < 10)
            result = "0" + result;
        result = time + ":" + result;
        return result;
    }
</script>
</div>